<?php

declare(strict_types=1);

namespace app\model;

use think\Model;
use think\model\concern\SoftDelete;

class SysConfig extends Model
{
    use SoftDelete;

    protected $name = 'sys_config';

    protected $autoWriteTimestamp = 'datetime';

    protected $hidden = ['delete_time'];

    public function getValue()
    {
        $value = $this->getAttr('config_value');
        switch ($this->getAttr('value_type')) {
            case 'json':
                return json_decode($value, true);
            case 'int':
                return (int)$value;
            case 'bool':
                return (bool)$value;
            case 'decimal':
            case 'float':
                return (float)$value;
            default:
                return $value;
        }
    }
}
